package com.sx.wechat.command.api;

import com.sx.core.utils.UUIDUtils;
import com.sx.core.vo.JsonReaderResponse;
import com.sx.core.vo.Params;
import com.sx.wechat.command.cmd.AbstractCommand;
import com.sx.wechat.security.AuthenticationHolder;
import com.sx.wechat.security.Principal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

/**
 * Created by lihao on 2018/9/25.
 */
@Component("sub_lesson_p")
public class Sub_lesson_p extends AbstractCommand {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public Object executeApi(HttpServletRequest request, HttpServletResponse response) {
        Principal principal= AuthenticationHolder.getCurrent();
        String lessonid=obtain(request,"lessonid");
        String content=obtain(request,"content");
        Params params=new Params();
        params.p("id", UUIDUtils.generateUuid32()).p("lessonid",lessonid).p("pcontent",content).p("pdate",new Date()).p("puserid",principal.getId());
        String sql="insert into t_lesson_reply (id,lessonid,puserid,pcontent,pdate) values (:id,:lessonid,:puserid,:pcontent,:pdate);";
        namedParameterJdbcTemplate.update(sql,params);
        return new JsonReaderResponse();
    }
}
